/** @description  请求接口api**/
/** @author  wutao **/
/** @date 2020-04-20 **/

import storage from './lib/storage/index'


let appApi = {};

const server = {
	test: 'test',
	produce: 'produce',
	bendi: 'bendi',
	yuyan: 'yuyan'
}
//  请求类型
appApi.requestType = {
	get: 'GET',
	post: 'POST',
}

appApi.server = server.yuyan;

//种植日历模块地址
appApi.plantingUrl = 'http://wx.lpht.cn/apiv0/';

appApi.baseUrl = {
	test: 'http://111.22.0.19:',
	produce: 'http://222.240.147.140:8555/nsy/',
	bendi: "http://192.168.1.200:8001/",
	yuyan: 'http://192.168.0.241:8000/'
}

/* 公共请求头 */
appApi.getCommonHeader = function(jsonhead) {
	// 判断系统类型
	let platform = uni.getSystemInfoSync().platform
	let tokenValue = ''
	if (storage.getToken() != null) {
		tokenValue = storage.getToken()
	}
	if (!jsonhead) {
		return {
			"ACCESS-TOKEN": tokenValue,
			'X-Hub-Sales-Platform': platform
		}
	}
	return {
		'content-type': 'application/json',
		"ACCESS-TOKEN": tokenValue,
		'X-Hub-Sales-Platform': platform
	}
}
//接口
appApi.api = {
	exsample: {
		url: appApi.baseUrl[appApi.server] + 'xxxxx',
		method: '', //
		header: {}, //请求头
	},
	// 登录
	// login: {
	// 	url: appApi.baseUrl[appApi.server] +
	// 		'apisApp/login',
	// 	method: appApi.requestType.post
	// },
	// 登录
	login: {
		url: appApi.baseUrl[appApi.server] +
			'api/web/login',
		method: appApi.requestType.post
	},
	// 获取订单
	getOrder: {
		url: appApi.baseUrl[appApi.server] +
			'api/web/order',
		method: appApi.requestType.post,
	},
	// 获取物料
	getBom: {
		url: appApi.baseUrl[appApi.server] +
			'api/web/bom',
		method: appApi.requestType.post,
	},
	
}

/*  获取请求配置项 */
appApi.getApi = (api, params, needHeader = true, jsonhead = true) => {
	let requestApi = appApi.api[api];
	requestApi['data'] = params;
	if (needHeader) {
		requestApi['header'] = appApi.getCommonHeader(jsonhead);
	}
	return requestApi;
}
export default appApi
